﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace MG1
{
    class Player : SpriteBase
    {
        public int hp;
        public int hpMax;

        public Vector2 mouseAim;
        public float mouseDirection;
        public float mouseDistance;

        Vector2 movement = Vector2.Zero;
        public float rotation = 0; //draw rotation from 0 to 2*Math.PI

        public Player(ContentManager _contentManager, string _assetName)
        {
            LoadContent(_contentManager, _assetName);

            hp = G.Setting.unitHp;
            hpMax = G.Setting.unitHp;
            Scale = 0.5f;
        }

        public void SetData(float _rotation)
        {
            rotation = _rotation;
        }


        public void HandleInput(InputManager input)
        {
            movement = Vector2.Zero;

            if (input.leftKeyDown)
                movement.X--;
            if (input.rightKeyDown)
                movement.X++;
            if (input.upKeyDown)
                movement.Y--;
            if (input.downKeyDown)
                movement.Y++;

            if (movement.Length() > 1)
                movement.Normalize();
        }

        public void Update(GameTime gameTime)
        {
            position += movement * (float)gameTime.ElapsedGameTime.TotalSeconds * G.Setting.unitSpeed;
            rotation = (float)QMath.V2ToAngle1(position, G.input.MousePosition2());

            //position += new Vector2(QMath.get_dx(speed, direction), QMath.get_dy(speed, direction)) * (float)gameTime.ElapsedGameTime.TotalSeconds;
        }

        public void Draw(SpriteBatch theSpriteBatch)
        {
            theSpriteBatch.Draw(texture, position, SourceSize, Color.White, rotation, new Vector2(texture.Width / 2, texture.Height / 2), Scale, SpriteEffects.None, 0);
        }
    }
}
